# This script produces Figure 1 # 
rm(list=ls())
options(digits=4)
pkg <- c("PanelMatch", "ggplot2", "plm", 
         "matrixStats",
         "foreign", 
         "stringi", "stringdist",
         "DataCombine","lmtest", "multiwayvcov",
         "data.table",
         "dplyr", 
         "stargazer",
         "clubSandwich", "mediation",
         "doBy")
lapply(pkg, require, character.only = TRUE)

# load datasets
proprietary <- read.csv("proprietary.csv")
load("non_p.RData")

# merge
d_sub1 <- merge(d_sub1, proprietary, by = c("county_id", "time"), all.x = T)

d1 <- d_sub1

d1$tour[d1$tour == 1] <- 100


panel_plot <- DisplayTreatment(unit.id = "county_id",
                               time.id = "time",
                               xlab = "Month", ylab = "County",
                               color.of.treated = "white",
                               color.of.untreated = "black",
                               legend.position = "none",
                               title = "Treatment Distribution \n Across Counties and Months",
                               legend.labels = c("No Inspection", "Under Inspection (Treatment)"),
                               # hide.x.axis.label = T,
                               hide.y.axis.label = T,
                               treatment = "tour", data = d1) + 
  theme(axis.text.y = element_blank(), 
        axis.ticks.y = element_blank(),
        text = element_text(size=20),
        axis.text.x = element_text(angle=0, size = 6.5, vjust=0.5),
        legend.title = element_blank(),
        rect = element_rect(fill = "transparent")) + 
  scale_y_discrete(breaks = c(12, 24, 36, 48, 60, 72),
                   labels = c("Dec \n 2012",
                              "Dec \n 2013",
                              "Dec \n 2014",
                              "Dec \n 2015",
                              "Dec \n 2016",
                              "Dec \n 2017"))


ggsave(file = "Dis_white_black.png", height = 12, width = 6, panel_plot,
       
       path = "output/") # save
